package com.rich.paas.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 列表复制工具类
 *
 * @author chenhao
 * @version 1.0
 * @date 2018/5/21 下午2:49
 */
public class ListCopyUtil<S, T> {

    private Class<T> targetType;

    public ListCopyUtil(Class<T> targetType) {
        this.targetType = targetType;
    }

    public List<T> copy(List<S> src) {
        List<T> target = new ArrayList<>();
        for (S s : src) {
            T t = BeanUtils.instantiateClass(targetType);
            BeanUtils.copyProperties(s, t);
            target.add(t);
        }
        return target;
    }
}